// 笔试强训day26：空调遥控

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n = 0, p = 0;
    cin >> n >> p;
    vector<int> team(n);
    int high = 0, low = 1000001;
    for(auto& e : team)
    {
        cin >> e;
        if(e > high) high = e;
        if(e < low) low = e;
    }

    vector<int> hash(high - low + 1, 0);
    for(auto e : team)
    {
        e -= low;
        int lbound = max(0, e - p), rbound = min(high - low, e + p) + 1;
        for(int i = lbound; i < rbound; i++)
        {
            ++hash[i];
        }
    }
    
    int maxnum = 0;
    for(auto& e : hash)
    {
        if(e > maxnum)
            maxnum = e;
    }
    cout << maxnum << endl;
}